'**************************************************************************
'*                  VfW 1.1 Runtime Setup
'**************************************************************************
'$INCLUDE 'setupapi.inc'
'$INCLUDE 'mscpydis.inc'    ''System
'$INCLUDE 'msdetect.inc'    ''Detects Avalilable Disk Space

''Dialog ID's
CONST WELCOME       = 100
CONST ASKQUIT       = 200
CONST EXITFAILURE   = 400
CONST EXITQUIT      = 600
CONST EXITSUCCESS   = 700
CONST APPHELP       = 900
CONST CHECK         = 2500
'CONST SMALLWIN      = 2200
CONST SMALLWIN      = 6300
CONST RESTART       = 2600
CONST RESTARTII     = 2700

''Bitmap ID
CONST LOGO = 1

GLOBAL SizeReq&  '' Total Disk Size required for installation

''File Types
GLOBAL WinDir$
GLOBAL WinSysDir$
GLOBAL WINDRIVE$    ''Windows Drive Letter.
GLOBAL CHECKSTATES$

DECLARE SUB Install
DECLARE FUNCTION MakePath (szDir$, szFile$) AS STRING
DECLARE FUNCTION OnWindowsNT LIB "INIUPD.DLL" AS INTEGER
DECLARE FUNCTION VflatdPresent LIB "iniupd.DLL" AS INTEGER
DECLARE FUNCTION IsValidEnvironment LIB "mscuistf.dll" () As INTEGER
DECLARE SUB Reboot LIB "iniupd.dll"
DECLARE fUNCTION ExitWindowsExec  LIB "User" (Exec$, Param$) AS INTEGER

Declare Sub CheckHardware
Declare function WritePrivateProfileString LIB "kernel" (lpszSection$,lpszEntry$,lpszString$,lpszFilename$) As Integer
Declare function GetPrivateProfileString LIB "kernel" (lpszSection$, lpszEntry$, lpszDefault$, lpszReturnBuffer$, cbReturnBuffer%, lpszFilename$) As Integer
Declare Function GetKeyboardType LIB "keyboard" (Keystute%) as integer

INIT:

    CUIDLL$ = "mscuistf.dll"            ''Custom user interface dll
    HELPPROC$ = "FHelpDlgProc"          ''Help dialog procedure

    WIN32ENABLED% = 0
    MajorVer% = GetWindowsMajorVersion()
    MinorVer% = GetWindowsMinorVersion()

    IsJP%=IsValidEnvironment()
    IF MajorVer% < 3 OR (MajorVer% = 3 AND MinorVer% < 10) THEN
        IF IsJP% THEN
            GOTO JPEXIT
        ELSE
            GOTO ENGEXIT
        ENDIF
    ELSEIF IsJP% = 0 THEN
        GOTO ENGEXIT
    END IF

    IF OnWindowsNT() THEN
      i% = DoMsgBox("このバージョンの Video for Windows は Windows NT 上で実行する事は出来ません。", "インストール上の注意", MB_OK+MB_TASKMODAL+MB_ICONHAND)
      END
    END IF

    SetBitmap CUIDLL$, LOGO
    SetTitle "Video for Windows 1.1 Runtime"

    szInf$ = GetSymbolValue("STF_SRCINFPATH")
    IF szInf$ = "" THEN
       szInf$ = GetSymbolValue("STF_CWDDIR") + "SETUP.INF"
    END IF
    ReadInfFile szInf$

    WINDRIVE$ = MID$(GetWindowsDir, 1, 1)


WELCOME:
    sz$ = UIStartDlg(CUIDLL$, WELCOME, "FInfoDlgProc", APPHELP, HELPPROC$)
    IF sz$ = "CONTINUE" THEN
       UIPop 1
     ELSE
    GOSUB ASKQUIT
    GOTO WELCOME
    END IF

''Prepare Copy list and check size

    ClearCopyList
    SrcDir$ = GetSymbolValue("STF_SRCDIR")
    WinDir$ = GetWindowsDir()
    DEST$ = GetWindowsDir()
    WinSysDir$ = GetWindowsSysDir()

''  Runtime files (on Windows disk)

    AddSectionFilesToCopyList "VfW Runtime", SrcDir$, WinSysDir$
    AddSectionFilesToCopyList "OLE2", SrcDir$, WinSysDir$
    AddSectionFilesToCopyList "ACM Drivers", SrcDir$, WinSysDir$
    AddSectionFilesToCopyList "MPlayer", SrcDir$, WinDir$
    AddSectionFilesToCopyList "AVICodecs", SrcDir$, WinSysDir$
''    AddSectionFilesToCopyList "Indeo-ini", SrcDir$, WinDir$   deleted indeo.ini  94/07/06

''  Check windrive diskspace
    SizeReq& = GetCopyListCost ("","", "")
    IF SizeReq& <> 0 THEN
    GOSUB SMALLWIN
    END
    END IF

Install

'' Restart Windows: if it has to updates ACM from DOS, it restarts Windows automatically
'' else, it gives the user the choice
    RESTRT% = RestartListEmpty ()
    Exe$ = DEST$ + "\_msrstrt.exe"
    Batch$ = DEST$ + "\_mssetup.bat"
    empty$ = ""
RESTART:
    IF RESTRT% = 0 THEN
       sz$ = UIStartDlg(cuidll$, RESTART, "FInfo0DlgProc", 0, "")
       IF sz$ = "REACTIVATE" THEN
      GOTO RESTART
       ENDIF
       I% = ExitExecRestart ()
       RemoveFile Exe$, cmoForce
       RemoveFile Batch$, cmoForce
       END
    ELSE
       sz$ = UIStartDlg(CUIDLL$, RESTARTII, "FQuitDlgProc", 0, "")
       IF sz$ = "CONTINUE" THEN
      I% = ExitWindowsExec (Exe$, empty$)
      IF I% = 0 THEN
         GOTO RESTART
      ELSE
         END
     ENDIF
       ELSEIF sz$ = "EXIT" THEN
      UIPopAll
      END
       ELSEIF sz$ = "REACTIVATE" THEN
      GOTO RESTART
       ELSE
      UIPop 1
       END IF
    END IF


QUIT:
    ON ERROR GOTO ERRQUIT

    IF ERR = 0 THEN
    dlg% = EXITSUCCESS
    ELSEIF ERR = STFQUIT THEN
    dlg% = EXITQUIT
    ELSE
    dlg% = EXITFAILURE
    END IF
QUITL1:
    sz$ = UIStartDlg(CUIDLL$, dlg%, "FInfo0DlgProc", 0, "")
    IF sz$ = "REACTIVATE" THEN
    GOTO QUITL1
    END IF
    UIPop 1
    END

ERRQUIT:
    i% = DoMsgBox("セットアップディスクのファイルが壊れています。サポートセンターまでご連絡下さい。", "セットアップ時に問題発生", MB_OK+MB_TASKMODAL+MB_ICONHAND)
    END


ASKQUIT:
    sz$ = UIStartDlg(CUIDLL$, ASKQUIT, "FQuitDlgProc", 0, "")

    IF sz$ = "EXIT" THEN
    UIPopAll
''        ERROR STFQUIT
    END
    ELSEIF sz$ = "REACTIVATE" THEN
    GOTO ASKQUIT
    ELSE
    UIPop 1
    END IF
    RETURN

SMALLWIN:
    sz$ = UIStartDlg(CUIDLL$, SMALLWIN, "FInfo0DlgProc", 0, "")
    IF sz$ = "REACTIVATE" THEN
    GOTO SMALLWIN
    END IF
    UIPop 1
    RETURN

JPEXIT:
    i% = DoMsgBox("このソフトウェアには、Microsoft Windows バージョン 3.1 以降が必要です。  Windows のバージョンアップを行ってください。", "インストール上の注意", MB_OK+MB_TASKMODAL+MB_ICONHAND)
    END
ENGEXIT:
   msg1$="Japanese version of Microsoft Windows version 3.1 or grater is required for this software. "
   msg2$="Please upgrade your version of Windows."
   i% = DoMsgBox( msg1$+msg2$ ,"Installation Problem", MB_OK+MB_TASKMODAL+MB_ICONHAND)
   END


'**
'** Purpose:
'**     Performs all installation operations.
'** Arguments:
'**     none.
'** Returns:
'**     none.
'*************************************************************************
SUB Install STATIC

    SetRestartDir WinDir$
    CopyFilesInCopyList

'' Copy ir32.dll to ir30.dll 
    CopyFile MakePath(WinSysDir$, "ir32.dll"), MakePath(WinSysDir$, "ir30.dll"), cmdOverwrite, 0

''Updating WIN.INI and SYSTEM.INI
    IF VflatdPresent() = 0 THEN
       CreateSysIniKeyValue WinDir$ + "system.ini", "386Enh", "device", "dva.386", cmoOverwrite
    END IF
    CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "VIDC.CVID", "iccvid.drv", cmoOverwrite
    CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "VIDC.MSVC", "msvidc.drv", cmoOverwrite
    CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "VIDC.IV31", "ir32.dll", cmoOverwrite
    CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "VIDC.IV32", "ir32.dll", cmoOverwrite
    CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "VIDC.RT21", "ir21.dll", cmoOverwrite
    CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "VIDC.YVU9", "iyvu9.dll", cmoOverwrite
    CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "VIDC.MRLE", "MSRLE.drv", cmoOverwrite
    CreateIniKeyValue WinDir$ + "WIN.INI", "mci extensions", "avi", "AVIVideo", cmoOverwrite
    CreateIniKeyValue WinDir$ + "system.ini", "mci", "AVIVideo", "mciavi.drv", cmoOverwrite
    CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "WaveMapper", "msacm.drv", cmoOverwrite
    CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "MSACM.msadpcm", "msadpcm.acm", cmoOverwrite
    CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "MSACM.imaadpcm", "imaadpcm.acm", cmoOverwrite
    CreateIniKeyValue WinDir$ + "control.ini", "drivers.desc", "msacm.drv", "Microsoft Sound Mapper V2.00", cmoOverwrite
    CreateIniKeyValue WinDir$ + "control.ini", "drivers.desc", "msadpcm.acm", "Microsoft ADPCM Codec V2.00", cmoOverwrite
    CreateIniKeyValue WinDir$ + "control.ini", "drivers.desc", "imaadpcm.acm", "Microsoft IMA ADPCM Codec V2.00", cmoOverwrite
    Run ("regedit.exe /s " + MakePath(WinDir$, "mplayer.reg"))
    Run ("regedit.exe /s " + MakePath(WinSysDir$, "OLE2.reg"))
    Run ("regedit.exe /s " + MakePath(WinSysDir$, "cleanup.reg"))

'' Mplayer
    CreateProgmanItem "アクセサリ", "メディア プレーヤー", MakePath(WinDir$, "mplayer.exe"), "", cmoOverwrite

CHECKFONT:
    DummyBuf$=STRING$(30," ")
    Res%=GetProfileString("fonts","ＭＳ ゴシック (TrueType)","",DummyBuf$,30)
    If(Len(DummyBuf$)=0)Then
      CRLF$=Chr$(13)
      Title1$="Video for Windows使用上の注意"
      Msg1$="Video for Windowsのプログラムは、ＭＳ ゴシックフォントを使用します。"
      Msg2$="このシステムには、ＭＳ ゴシックフォントが組み込まれていないので、プログラムの表示が乱れる可能性があります。"
      Msg3$="正しい動作をさせるためには、[コントロールパネル]の[フォント]からＭＳ ゴシックフォントを組み込んでください。"
      i% = DoMsgBox(Msg1$+CRLF$+Msg2$+CRLF$+Msg3$, Title1$, MB_OK+MB_TASKMODAL+MB_ICONEXCLAMATION)
    End if

    CheckHardware
    
    Run ("profdisp.exe")
END SUB

'**
'** Purpose:
'**     Appends a file name to the end of a directory path,
'**     inserting a backslash character as needed.
'** Arguments:
'**     szDir$  - full directory path (with optional ending "\")
'**     szFile$ - filename to append to directory
'** Returns:
'**     Resulting fully qualified path name.
'*************************************************************************
FUNCTION MakePath (szDir$, szFile$) STATIC AS STRING
    IF szDir$ = "" THEN
    MakePath = szFile$
    ELSEIF szFile$ = "" THEN
    MakePath = szDir$
    ELSEIF MID$(szDir$, LEN(szDir$), 1) = "\" THEN
    MakePath = szDir$ + szFile$
    ELSE
    MakePath = szDir$ + "\" + szFile$
    END IF
END FUNCTION


'**
'**
'*************************************************************************
Sub CheckHardware STATIC
MAX_NODVADISP% = 4
Dim NoDVADrivers(4) As String
NoDVADrivers(0) = "VGA488T.drv"    ' Compaq Prolinea ET4000/W32 Driver
NoDVADrivers(1) = "VGA488.drv"     ' Compaq Prolinea ET4000 Driver
NoDVADrivers(2) = "VGA4A8T.drv"    ' Compaq Prolinea ET4000/W32 Driver
NoDVADrivers(3) = "VGA4A8.drv"     ' Compaq Prolinea ET4000 Driver

      keySubType% = GetKeyboardType(1)
      If(keySubType%>=3329 and keySubType%<=3332)Then
          '==== HardWare is NEC PC98 Series
          res% = WritePrivateProfileString("drawdib","dva","0","win.ini")
      elseIf(keySubType%>=0 and keySubType%<=4)Then
          '==== Hardware is DOSV Machine
          res% = WritePrivateProfileString("drawdib","dva","1","win.ini")
      elseif(keySubType%=1281)then
          '==== Hardware is FUJITSU FM-TOWNS Only
          res% = WritePrivateProfileString("drawdib","dva","0","win.ini")
      else
          res% = WritePrivateProfileString("drawdib","dva","0","win.ini")
      end if

    NowDispDrvName$ = STRING$(15," ")
    res% = GetPrivateProfileString("boot","display.drv","",NowDispDrvName$,15,"system.ini")
    CntNum% = 0
    While (CntNum% < MAX_NODVADISP%)
      If(Ucase$(NowDispDrvName$)=Ucase$(NoDVADrivers(CntNum%)))Then
          res% = WritePrivateProfileString("drawdib","dva","0","win.ini")
      End If
      CntNum% = CntNum% + 1
    Wend  


End Sub
